
# Plug
# ────────────────────────────────────────────────────
evaluate-commands %sh{
	plugins="$kak_config/plugins"
  mkdir -p "$plugins"
  [ ! -e "$plugins/plug.kak" ] && \
  git clone -q https://github.com/andreyorst/plug.kak.git "$plugins/plug.kak"
  printf "%s\n" "source '$plugins/plug.kak/rc/plug.kak'"
}
plug "andreyorst/plug.kak" noload

# Loads & Sources
# ────────────────────────────────────────────────────
source "%val{config}/kakrc.local"
require-module prelude
require-module connect

# General Settings
# ────────────────────────────────────────────────────
colorscheme gotham

set-option global makecmd 'make -j 8'
set-option global grepcmd 'rg --column'
set-option global tabstop 2
set-option global indentwidth 2
set-option global autoreload ask
add-highlighter global/ wrap -indent -marker ⎁ -width 100
add-highlighter global/ show-matching
set-option global scrolloff 8,3
set-option global ui_options terminal_set_title=false terminal_status_on_top=false terminal_assistant=none terminal_enable_mouse=true terminal_change_colors=true    terminal_builtin_key_parser=false

# Hooks
# ────────────────────────────────────────────────────
hook   global WinSetOption filetype=(sh|javascript|typescript|lua|nix) %{ lsp-enable-window }
hook   global WinCreate .* %{ enable-auto-pairs }
hook   global WinCreate .*.nix %{ set-option buffer formatcmd alejandra
 }
hook   global BufWritePre .*.nix %{ format }
hook   global WinCreate .* %{ kakboard-enable }

# Fuzzy-Finder
# ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
plug "https://github.com/andreyorst/fzf.kak" config %{
  map global normal <c-p> ': fzf-mode<ret>' -docstring "fzf mode"
}

# Auto-Pairs
# ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
plug "https://github.com/alexherbo2/auto-pairs.kak"

# LSP Server
# ────────────────────────────────────────────────────
try %sh{ kak-lsp --kakoune -s $kak_session }

# Buffers
# ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
try %{
  map global normal ^ q
  map global normal <a-^> Q
  map global normal q b
  map global normal Q B
  map global normal <a-q> <a-b>
  map global normal <a-Q> <a-B>
  map global normal b ': enter-buffers-mode<ret>' -docstring 'buffers'
  map global normal B ': enter-user-mode -lock buffers<ret>' -docstring 'buffers (lock)'
}

# Wiki
# ────────────────────────────────────────────────────
plug "https://github.com/TeddyDD/kakoune-wiki"

# Filetypes
# ────────────────────────────────────────────────────
hook global BufCreate .+[rc|\.local|\.conf|\.sh] %{
  set-option buffer filetype sh
}

# Keybinding
# ────────────────────────────────────────────────────
hook global InsertChar j %{ try %{
  exec -draft hH <a-k>kj<ret> d
  exec <esc>
}}

map global normal '#' :comment-line<ret> -docstring 'comment line'
map global normal '<a-#>' :comment-block<ret> -docstring 'comment block'
map global normal = :format<ret> -docstring 'format buffer'

map global user | ':tmux-terminal-horizontal kak -c %val{session}<ret>' -docstring 'split H'
map global user = ':tmux-terminal-vertical kak -c %val{session}<ret>' -docstring 'split V'
map global user 'f' ": kaktree-toggle<ret>" -docstring "toggle filetree panel"
map global user l ': enter-user-mode lsp<ret>' -docstring 'lsp'

